////////////////////////////////////////////////////////////////////////////////
//
//  FLYING KIWI BV
//  Copyright 2010 Flying Kiwi BV
//  All Rights Reserved.
//
//  NOTICE: Flying Kiwi permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package plantool.modules.users.display {
	import caurina.transitions.Tweener;
	import caurina.transitions.properties.ColorShortcuts;
	
	import flash.display.GradientType;
	import flash.geom.Matrix;
	
	import kiwi.components.DragObject;
	import kiwi.components.IDropTarget;

	//--------------------------------------------------------------------------
	//  Imports
	//--------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	//  [Metadata (Events, Style, Effects etc)]
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//  Class declaration
	//--------------------------------------------------------------------------
	public class UserDay extends UserDisplayObject implements IUserDay, IDropTarget {
		//--------------------------------------------------------------------------
		//Class constants
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//Class variables
		//--------------------------------------------------------------------------
		private var _date:Date		= null;
		
		//--------------------------------------------------------------------------
		//Class properties
		//--------------------------------------------------------------------------
		public function get date():Date {
			return _date;
		}
		public function set date(value:Date):void {
			_date = new Date(value);
		}
		
		public override function get width():Number {
			return 162;
		}
		
		//--------------------------------------------------------------------------
		//Constructor and Destructor
		//--------------------------------------------------------------------------
		public function UserDay() {
			super();
			ColorShortcuts.init();
		}
		
		public override function dispose():void {
			//unset vars
			_date = null;
			
			//super dispose
			super.dispose();
		}
		
		//--------------------------------------------------------------------------
		//Class methods
		//--------------------------------------------------------------------------
		protected override function init():void {
			super.init();
		}
		
		public function addHour(hour:IUserHour):void {
			//position hour
			(hour as UserHour).x = (hour.date.hours - dateApi.dayStartHour) * 20;
			
			//add hour
			addChild(hour as UserHour);
		}
		
		public function dragObjectOver(target:DragObject):void {
			Tweener.addTween(this, { _autoAlpha: 0.4, time: .25 });
		}
		
		public function dragObjectOut(target:DragObject):void {
			Tweener.addTween(this, { _autoAlpha: 1, time: .25 });
		}
		
		public override function draw():void {
			//create button graphics
			graphics.clear();
			graphics.beginFill(user.color, 0.35);
			graphics.drawRect(0, 0, 160, 20);
			graphics.endFill();
			
			var myMatrix:Matrix = new Matrix();
			myMatrix.createGradientBox(160, 20, Math.PI / 4, 0, 0);
			var colors:Array = [0xFFFFFF, 0xFFFFFF];
			var alphas:Array = [0.4, 0.6];
			var ratios:Array = [0, 255];
			
			graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, myMatrix);
			graphics.drawRect(0, 0, 160, 20);
			graphics.endFill();
			
			graphics.beginFill(0);
			graphics.drawRect(160, 0, 2, 20);
			graphics.endFill();
		}
	}
}